﻿using UnityEngine;
using System.Collections;

public class UIViewAutoWH : UIViewAuto
{
		public double relativeWH = 0;

		public override void setAutoScaleX (float autoScaleX)
		{
				if (relativeWH > 0) {
						float currentScaleX = UIScreen.getScreenScaleX ();
						if (currentScaleX != 0 && relativeWH > currentScaleX) {
								Camera uiCamera = UIScreen.getScreenCamera ();
								float scaleX = uiCamera.pixelWidth / uiCamera.pixelHeight;
								if (scaleX > currentScaleX) {
										if (scaleX > relativeWH) {
												scaleX = (float)relativeWH;
										}

										scaleX /= currentScaleX;
										Vector3 localScale = transform.localScale;
										localScale.x *= scaleX;
										localScale.y *= scaleX;
										localScale.z *= scaleX;
										transform.localScale = localScale;
										if (transform.localPosition.y != 0) {
												localScale = transform.localPosition;
												localScale.y *= scaleX;
												transform.localPosition = localScale;
										}

										autoScaleX *= scaleX;
								}
						}
				}

				base.setAutoScaleX (autoScaleX);
		}
}
